define(function(require, exports, module) {

  // var Backbone = require('backbone');
  var $ = require('jquery');
  var _ = require('underscore');
  // var jsonview = require('jsonview');
  var tmpl = require('text!../tmpl.html');

  function main() {
    var $app = $('<div id="app">');
    $('#main').html($app);

    $app.append(tmpl);

    domainData('http://192.168.137.1:7700/test/html', function(data) {
      alert(data);
    });

    function domainData(url, fn) {
      var isFirst = true;
      var iframe = document.createElement('iframe');
      // iframe.style.display = 'none';
      var loadfn = function() {
        if (isFirst) {
          iframe.contentWindow.location = 'http://localhost/templet/blank/'; //2. 同域
          isFirst = false;
        } else {
          fn(iframe.contentWindow.name); //通过window.name来传递数据
          // iframe.contentWindow.document.write('');
          // iframe.contentWindow.close();
          // document.body.removeChild(iframe);
          // iframe.src = '';
          // iframe = null;
        }
      };

      iframe.src = url; //1. 其他域
      
      if (iframe.attachEvent) {
        iframe.attachEvent('onload', loadfn);
      } else {
        iframe.onload = loadfn;
      }

      $app.append(iframe);
    }
  }
  
  return main;
})
